<?php

class VideoAction extends AdministratorAction {
	/**
	 * 视频模型
	 * @var obj
	 */
	protected $modelObj = null;
	
	/**
	 * 初始化控制器
	 * @see AdministratorAction::_initialize()
	 */
	public function _initialize(){
		parent::_initialize();
		$this->modelObj = D('Video');
	}
	
	/**
	 * 视频列表页
	 */
	public function index(){
		load('extend');
		import('ORG.Util.Page');
		//每页显示数
		$perpage = C('PER_PAGE');
		$keyword = $this->_get('keyword');
		$where = array();
		if ( $keyword !='' ){
			$where[] = "title LIKE '%$keyword%'";
			$where[] = "description LIKE '%$keyword%'";
		}
		
		$where_str = implode(' OR ', $where);
		$count = $this->modelObj->where($where_str)->count();
		$Page = new Page($count,$perpage);
		$show = $Page->show();
		$videos = $this->modelObj->where($where_str)->limit($Page->firstRow.','.$Page->listRows)->select();
		$this->assign('videos',$videos);
		$this->assign('page',$show);
		$this->display();
	}
	
	/**
	 * 添加或编辑视频
	 * @see AdministratorAction::edit()
	 */
	public function edit(){
		$vid = $this->_request('vid');
		if ( $this->isPost() ){
			if ( !$this->modelObj->create() ){
				$this->error($this->modelObj->getError());
			}
			$id = $this->modelObj->add();
			if ( !$id ){
				$this->error('系统错误');
			}
		}
		else {
			$this->display('Video:edit');
		}
	}
	
	protected  function _checkFormData(){
		
	}
}